
#include "comm/comm_socket.h"

#ifdef WIN32

#pragma comment(lib, "ws2_32.lib")
//typedef int socklen_t;

int socket_init(void)
{
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;

	wVersionRequested = MAKEWORD( 2, 2 );

	err = WSAStartup( wVersionRequested, &wsaData );
	if ( err != NO_ERROR )
	{
		/* Tell the user that we could not find a usable */
		/* WinSock DLL.                                  */
		return err;
	}

	/* Confirm that the WinSock DLL supports 2.2.*/
	/* Note that if the DLL supports versions later    */
	/* than 2.2 in addition to 2.2, it will still return */
	/* 2.2 in wVersion since that is the version we      */
	/* requested.                                        */

	if ( LOBYTE( wsaData.wVersion ) != 2 ||
		HIBYTE( wsaData.wVersion ) != 2 )
	{
		/* Tell the user that we could not find a usable */
		/* WinSock DLL.                                  */
		WSACleanup( );
		return WSAGetLastError();
	}

	/* The WinSock DLL is acceptable. Proceed. */
	return 0;
}

sockfd udp_create(void)
{
	return socket(AF_INET, SOCK_DGRAM, 0);
}

#else

int socket_init(void)
{
	return 1;
}

sockfd udp_create(void)
{
	return socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
}

#endif
